<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	<%@  taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
	<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html lang="en">
<%@ include file="common/head.jsp"%>

<body class="fix-header fix-sidebar">

	<!-- Preloader - style you can find in spinners.css -->
	<div class="preloader">
		<svg class="circular" viewBox="25 25 50 50">
				<circle class="path" cx="50" cy="50" r="20" fill="none"
				stroke-width="2" stroke-miterlimit="10" /> </svg>
	</div>
	<!-- Main wrapper  -->
	<div id="main-wrapper">
		<!-- header header  -->
		<%@ include file="common/header.jsp"%>
		<!-- End header header -->
		<!-- Left Sidebar  -->
		<%@ include file="common/nav.jsp"%>
		<!-- End Left Sidebar  -->
		<!-- Page wrapper  -->
		<div class="page-wrapper">
		<!-- 锐高软件 -->
			 <%@ include file="../common/ruigao.jsp" %>
			
			<!--
                    	作者：offline
                    	时间：2018-03-26
                    	描述：更新员工信息
                    -->
			<div class="container-fluid">
						<!-- Start Page Content -->
						<div class="row justify-content-center">
							<div class="col-lg-12">
								<div class="card">
									<div class="card-body">
										<div class="card-content">
											<!-- Left sidebar -->
											<div class="inbox-leftbar">

												<a href="${pageContext.request.contextPath}/user_list.jsp" class="btn btn-danger btn-block waves-effect waves-light">
													<font style="vertical-align: inherit;">
														<font style="vertical-align: inherit;">员工查看</font>
													</font>
												</a>
											</div>
											<!-- End Left sidebar -->
											<div class="inbox-rightbar">
												<div class="" role="toolbar">
													<div class="btn-group">
														<button type="button" class="btn btn-light waves-effect"><i class="mdi mdi-archive font-18 vertical-middle"></i></button>
														<button type="button" class="btn btn-light waves-effect"><i class="mdi mdi-alert-octagon font-18 vertical-middle"></i></button>
														<button type="button" class="btn btn-light waves-effect"><i class="mdi mdi-delete-variant font-18 vertical-middle"></i></button>
													</div>

												

												</div>
											</div>
										</div>
									</div>
									<div class="form-validation">
										<form class="form-valide col-lg-8" id="form" method="post" novalidate="novalidate" style="margin: 0 auto;">
											<c:forEach var ="user" items="${userlist}">
											
									        <input type="hidden" id="val-userid" name="val-userid" value="${user.userId }">
											<input type="hidden" id="val-opt" name="opt" value="">
											<div class="form-group row">
												<label class="col-lg-2 col-form-label" for="val-username">姓名 <span class="text-danger">*</span></label>
												<div class="col-lg-10">
													<input type="text" class="form-control" id="val-username" name="val-username" value="${user.userName}" >
												</div>
											</div>
											<div class="form-group row">
												<label class="col-lg-2 col-form-label" for="val-username">登陆名 <span class="text-danger">*</span></label>
												<div class="col-lg-10">
													<input type="text" class="form-control" id="val-loginname" name="val-loginname" value="${user.loginName}">
												</div>
											</div>
											<div class="form-group row">
												<label class="col-lg-2 col-form-label" for="val-username">登陆密码<span class="text-danger">*</span></label>
												<div class="col-lg-10">
													<input type="password" class="form-control" id="val-loginpwd" name="val-loginpwd"  value="${user.loginPwd}">
												</div>  
											</div>
											
											
											<div class="form-group row">
												<label class="col-lg-2 col-form-label" for="val-email">邮箱 <span class="text-danger">*</span></label>
												<div class="col-lg-10">
													<input type="text" class="form-control" id="val-email" name="val-email" value="${user.userEmail}" >
												</div>
											</div>		                        
											<div class="form-group row">
													<label class="col-lg-2 col-form-label" for="val-password">性别</label>
													<div class="col-lg-10">
												    
												   
												
																					
												<c:choose>
												         <c:when test="${user.userSex eq 1}">
													     
													      <input type="text" class="form-control" id="val-email" name="val-sex" value="男" >
												
													     
														</c:when>
														<c:otherwise>
														
														<input type="text" class="form-control" id="val-email" name="val-sex" value="女" >
													
														</c:otherwise>
																					
												</c:choose>

												
												</div>
												</div>
										
										  
											<div class="form-group row">
												<label class="col-lg-2 col-form-label" for="val-phone">手机号 <span class="text-danger">*</span></label>
												<div class="col-lg-10">
													<input type="text" class="form-control" id="val-phone" name="val-phone" value="${user.userPhone}" >
												</div>
											</div>
											<div class="form-group row">
												<label class="col-lg-2 col-form-label" for="val-suggestions">地址 <span class="text-danger">*</span></label>
												<div class="col-lg-10">
												<input type="text" class="form-control" id="val-aress" name="val-aress"  value="${user.userAddress}">
												</div>
											</div>
													
											<div class="form-group row">
												<label class="col-lg-2 col-form-label" for="val-currency">身份证号 <span class="text-danger">*</span></label>
												<div class="col-lg-10">
													<input type="text" class="form-control" id="val-userIdentitycard" name="val-userIdentitycard" value="${user.userIdentitycard}">
												</div>
											</div>
											<div class="form-group row">
												<label class="col-lg-2 col-form-label" for="val-phone">家属联系方式 <span class="text-danger">*</span></label>
												<div class="col-lg-10">
													<input type="text" class="form-control" id="val-familyphone" name="val-familyphone" value="${user.userFamilyphone}">
												</div>
											</div>
											<div class="form-group row">
												<label class="col-lg-2 col-form-label" for="val-number">出身年月<span class="text-danger">*</span></label>
												<div class="col-lg-10">
													<input type="date" class="form-control" id="val-date" name="val-date" value="<fmt:formatDate  type="both" value="${user.userEntrytime}" pattern="yyyy-MM-dd" />"/>
												</div>
											</div>
											<div class="form-group row">
												<label class="col-lg-2 col-form-label" for="val-phoneus">学历 <span class="text-danger">*</span></label>
												<div class="col-lg-10">
													<select class="form-control" id="val-userdiploma" name="val-userdiploma">
														<option value="${user.userDiploma}">${user.userDiploma}</option>
														<option value=初中>初中</option>
														<option value="高中">高中</option>
														<option value="大专">大专</option>
														<option value="本科">本科</option>

													</select>
												</div>
											</div>
											<div class="form-group row">
												<label class="col-lg-2 col-form-label" for="val-digits">职位 <span class="text-danger">*</span></label>
												<div class="col-lg-10">
													<input type="text" class="form-control" id="val-position" name="val-position" value="${user.userPosition}">
												</div>
											</div>
											<%@ include file="../listall/selectcompanyname.jsp" %>
											
											<div class="form-group row">
												<label class="col-lg-2 col-form-label" for="val-skill">所属部门 <span class="text-danger">*</span></label>
												<div class="col-lg-10">
													<select class="form-control" id="val-dept" name="val-dept">
													 </select>
												</div>
											</div>	
											

											

											<div class="form-group row">
												<div class="col-lg-8 ml-auto">
													<button type="button" class="btn btn-success btn sweet-tijiao ">更新</button>
													<button type="reset" class="btn btn-primary ">重置</button>
												</div>
											</div>
											
											
											</c:forEach>
									 </form>
									</div>
								</div>
							</div>
						</div>
						<!-- End PAge Content -->
					</div>
			
		</div>
	</div>
	<!-- End Container fluid  -->
	<!-- footer -->
	<%@ include file="common/footer.jsp"%>
	<!-- End footer -->
	<!-- End Page wrapper  -->
	<%@ include file="common/js.jsp"%>
    <script type="text/javascript">
     $(function(){
    	 //初始化加载
    	var options = $("#val-company option:selected");
 		var companyid= parseInt(options.val());
 		var companyname = options.text();		
 		var selectcompanyopt=$("#opt").val("selectcompanyid");
 		 $.ajax({
  	    	url:"companyid",
  	    	data:{"companyid":companyid},
  	    	type:"GET",
  	    	dataType:"json",
  	    	success:function(data){
  	        	$("#val-dept").text("");
  	        	for(var i in data){
  	       			$("#val-dept").append("<option value="+data[i].deptId+">"+data[i].deptName+"</option>");
  	        	}
  	    	},
  	    	error:function(data){
  	    		 swal({
 			            title:'操作失败！',		           
 			            type:'error',
 			            confirmButtonText:'确定',
 			            closeOnConfirm:false
 			         });
  	    	}
  	    });
    	 //获取选择的公司
     	$("#val-company").change(function(){
     		var options = $("#val-company option:selected");
     		var companyid= parseInt(options.val());
     		var companyname = options.text();
     		
     		var selectcompanyopt=$("#opt").val("selectcompanyid");
     	    $.ajax({
     	    	url:"companyid",
     	    	data:{"companyid":companyid},
     	    	type:"GET",
     	    	dataType:"json",
     	    	success:function(data){
     	        $("#val-dept").text("");
     	        for(var i in data){
     	       $("#val-dept").append("<option value="+data[i].deptId+">"+data[i].deptName+"</option>");
     	        }
     	    	},errot:function(data){
     	    		 swal({
  			            title:'操作失败！',		           
  			            type:'error',
  			            confirmButtonText:'确定',
  			            closeOnConfirm:false
  			         });
     	    	}
     	    });
     		});
    	 //点击更新
    	 $(".sweet-tijiao ").click(function(){
    		 
    		 $("#val-opt").val("UpDateUser");
    		var opt= $("#val-opt").val();
    		$.ajax({
    			url:"userServlet",
    			data:$("#form").serialize(),
    			type:"GET",
    			dataType:"JSON",
    			success:function(data){
    				if(data){
    					swal(
 								{
 										title : "更新成功!",
 										type:'success',
 										 text: "返回列表查看？", 
 										showCancelButton : true,
 										closeOnConfirm : false,
 										cancelButtonText : "取消",
 										confirmButtonText : "确定"
 									},
 									function(inputValue) {
 										if (inputValue === true){
 									     location.href="${pageContext.request.contextPath}/userServlet";
 										}else{
 											return false;
 										}
 									});		
    				}
    			},error:function(data){
    				swal({
   			            title:'更新失败！',		           
   			            type:'error',
   			            confirmButtonText:'确定',
   			            closeOnConfirm:false
   			         });
    			}
    			
    			
    			
    		});
    	 });
    	 
     });
    
    </script>
</body>

</html>